﻿@model IEnumerable<MSD.WL.Site.Models.InvenType>

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div style="padding-top:10px;padding-left:15px;padding-right:15px;">
@using (Html.BeginForm("Index", "InvenTypes", FormMethod.Post,new { id="searchForm"}))
{
    @Html.AntiForgeryToken()
    <div class="form-group-sm">
        <div class="col-sm-2">
            <input type="text" name="inventypecode" class="form-control" placeholder="请输入查询代码" /><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
        </div>
        <div class="col-sm-2">
            <input type="text" name="inventypename" class="form-control" placeholder="请输入查询名称" />
        </div>
        <button type="button" id="searchButton" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询</button><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <!-- Button trigger modal -->
        <button type="button" id="triggerModal-btn" class="btn btn-success btn-sm" data-toggle="modal" data-target="#EmsModal"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</button>
        <input type="hidden" id="PageIndex" name="PageIndex" value="0" />
        
    </div>
}
   <br />

    @*@Html.ActionLink("Create New", "Create")*@
    <table class="table table-bordered table-hover">
        <thead class="thead-light">
            <tr>
                <th scope="col">
                    @Html.DisplayNameFor(model => model.InvenTypeCode)
                </th>
                <th scope="col">
                    @Html.DisplayNameFor(model => model.InvenTypeName)
                </th>
                <th scope="col">操作</th>
            </tr>
        </thead>


        @foreach (var item in Model)
        {
            <tbody>
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.InvenTypeCode)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.InvenTypeName)
                    </td>
                    <td>
                        <a href="#" onclick="update(@(item.ID),'Edit','InvenTypes')"><span>修改</span></a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="#" onclick="update(@(item.ID),'Delete','InvenTypes')"><span>删除</span></a>
                    </td>
                </tr>
            </tbody>
        }
    </table>
    @*分页*@
    <nav id="pagebar" style="float:right" aria-label="Page navigation example">
        <ul class="pagination justify-content-end">
            <li class="page-item disabled">
                <span class="page-link">共@(ViewBag.PageCount)页&nbsp;&nbsp;当前第@(ViewBag.PageIndex+1)/@(ViewBag.PageCount)页</span>
            </li>
            <li id="firstPage" class="page-item">
                <a class="page-link" href="#" onclick="GoPage(@(ViewBag.PageCount),'firstPage')" tabindex="-1">首页</a>
            </li>
            <li id="previous" class="page-item">
                <a class="page-link" href="#" onclick="GoPage(@(ViewBag.PageCount),'previous')" tabindex="-1">上一页</a>
            </li>
            @for (var i = 0; i < ViewBag.PageCount; i++)
            {
                if (i == ViewBag.PageIndex)  //若为当前分页，则显示为文本
                {
                    <li id="currentpagenumber" class="page-item disabled"><a  class="page-link" href="#">@(i+1)</a></li>
                }
                else  //若为其他分页，则显示为链接
                {
                       <li id="pagenumber" class="page-item"><a class="page-link" href="#">@(i + 1)</a></li>
                }
            }
            <li id="next" class="page-item">
                <a class="page-link" href="#" onclick="GoPage(@(ViewBag.PageCount),'next')" >下一页</a>
            </li>
            <li id="lastPage" class="page-item">
                <a class="page-link" href="#" onclick="GoPage(@(ViewBag.PageCount),'lastPage')" tabindex="-1">尾页</a>
            </li>
        </ul>
    </nav> 
</div>

@{ Html.RenderPartial("_EmsModal");}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
<script src="~/scripts/jquery-1.10.2.min.js"></script>
<script src="~/scripts/bootstrap.min.js"></script>
<!--全局Js文件-->
<script type="text/javascript">
        //模态框关闭后刷新界面，防止模态框再次打开时无法被找到
        $(function () {
            $("#EmsModal").on("hidden.bs.modal", function () {
                window.location.reload();
            });
        });
        //模态框拖动
        $("#EmsModal #modal-header").mousedown(function (e) {
        var isDrag = false;//是否可以拖拽
        var ev = e || window.event;
        var ol = $(this).offset().left;//盒子最左边 距离 窗口最左边 的距离
        var ot = $(this).offset().top;
        var l = $(this).parent().css("left");
        var t = $(this).parent().css("top");
        deltaX = ev.pageX - parseInt(l);//鼠标 距离 盒子最左边 的距离
        deltaY = ev.pageY - parseInt(t);
        isDrag = true;
        var _this = $(this).parent();
        $(document).mousemove(function (e) {
        var ev = e || window.event;
        if (isDrag) {
        moveL = ev.pageX - deltaX;
        moveT = ev.pageY - deltaY;
        _this.css({
        "left": moveL,
        "top": moveT
        });
        }
        });
        $(document).mouseup(function () {
        isDrag = false;
        });
        });
</script>
<!--全局Js文件-->
<!--InvenTypes-->
<script type="text/javascript">
        ///

        function update(id, action, controller) {
            var currentId = id;
            switch (action) {
                case "Edit":
                    $.post("/" + controller + "/GetEdit" + controller + "", { id: currentId }).success(function (data) {
                        $("#EmsModal #EmsModalPreview").html(data);
                    });
                    $("#EmsModal #EmsModalLabel").text("修改");
                    $("#EmsModal #operateEmsModal-btn").text("保存");
                    $("#EmsModal").modal('show');
                    $("#EmsModal").on("click", "#operateEmsModal-btn", function () {
                        $("#EmsModal #Edits" + controller + "Form").submit();
                    });
                    break;
                case "Delete":
                    $.post("/" + controller + "/GetDelete" + controller + "", { id: currentId }).success(function (data) {
                        $("#EmsModal #EmsModalPreview").html(data);
                    });
                    $("#EmsModal #EmsModalLabel").text("删除");
                    $("#EmsModal #operateEmsModal-btn").text("确定");
                    $("#EmsModal").modal('show');
                    $("#EmsModal").on("click", "#operateEmsModal-btn", function () {
                        $("#EmsModal #Delete" + controller + "Form").submit();
                    });
                    break;
                default:
                    break;
            }
        }

        /*InvenTypes*/
        $(function () {
            $("#triggerModal-btn").click(function () {
                $("#EmsModal #EmsModalLabel").text("添加分类");
                $("#EmsModal #operateEmsModal-btn").text("保存");
                $("#EmsModal #EmsModalPreview").load('@Url.Action("GetCreateInvenTypes")');
                $("#categoryModal").modal('show');
            });
            $("#EmsModal").on("click", "#operateEmsModal-btn", function () {
                $("#EmsModal #CreateInvenTypesForm").submit();
            });
        });
        /*分页检索脚本*/
        function submitForm(pagenumber) {
            var pagenumber = parseInt(pagenumber, 10);
            $("#PageIndex").val(pagenumber - 1);
            $("#searchForm").submit();
        }
        $(function () {
            if ($("#pagebar #currentpagenumber").text() == "1") {
                $("#pagebar #previous").addClass("disabled");
                $("#pagebar #firstPage").addClass("disabled");
            }
            $("#searchButton").click(function () {
                submitForm($("#pagebar #currentpagenumber").text());
            });
            $("#pagebar #pagenumber").click(function () {

                    submitForm($(this).text());
            });
            //var currentnumber = parseInt($("#pagebar #currentpagenumber").text(), 10);
            @*if (currentnumber==@ViewBag.PageCount;)
            $("#pagebar #pnext").addClass("disabled")*@

            //});
            //$("#pagebar #next").click(function () {
            //    submitForm(currentnumber + 1);
            //});
        });

        //上下页分页函数
        function GoPage(pagecount,action) {
            var currentnumber = parseInt($("#pagebar #currentpagenumber").text(), 10);
            pageCount = pagecount;
            switch (action) {
                case 'previous':
                    submitForm(currentnumber - 1);
                    break;
                case 'next':
                    if (currentnumber == pagecount){
                        $("#pagebar #next").addClass("disabled");
                        $("#EmsModal #EmsModalLabel").text("提示");
                        $("#EmsModal #operateEmsModal-btn").text("确定");
                        $("#EmsModal #EmsModalPreview").text("已经是最后一页了");
                        $("#EmsModal").modal('show');
                        $("#EmsModal").on("click", "#operateEmsModal-btn", function () {
                            $("#EmsModal").modal('hide');
                        });
                        //alert()

                    }
                    else
                    submitForm(currentnumber + 1);
                    break;
                case 'firstPage':
                    submitForm(1);
                    break;
                case 'lastPage':
                    if (currentnumber == pagecount) {
                        $("#pagebar #lastPage").addClass("disabled");
                        $("#EmsModal #EmsModalLabel").text("提示");
                        $("#EmsModal #operateEmsModal-btn").text("确定");
                        $("#EmsModal #EmsModalPreview").text("已经是最后一页了");
                        $("#EmsModal").modal('show');
                        $("#EmsModal").on("click", "#operateEmsModal-btn", function () {
                            $("#EmsModal").modal('hide');
                        });
                    }
                    else
                    submitForm(pagecount);
                default:
                    break;
            }
        }
        /*分页检索脚本*/
        /*InvenTypes*/
</script>
}

